- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.6k
 
[dotnet] Make internal console writer more flexible via taking TextWriter only #15346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dotnet] Make internal console writer more flexible via taking TextWriter only #15346
Conversation
          PR Reviewer Guide 🔍Here are some key observations to aid the review process: 
  | 
    
          PR Code Suggestions ✨Explore these optional code suggestions: 
  | 
    |||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the TextWriterHandler is a good idea, however the existing ConsoleLogHandler is used by users. We would need to keep a type that just points to the text writer handler:
public class ConsoleLogHandler : TestWriterHandler(Console.Error);Additionally, TestWriterHandler(Console.Error) is not the same as ConsoleLogHandler if a user uses the Console.SetError method. The current code would point to whatever the new Console.Error pointed to, but this PR would still point to the old sink.
          
 True, and it is still good. As a low-level library we want to give user a power. Since this is "internal/advanced" thing, I am OK with this behavior. 
 OK, let's keep it and proceed via standard deprecation policy. Thank you, it is really better than just break.  | 
    
User description
Consoleis an output. We can be more extendable/abstract/generic.Motivation and Context
Taking minimal required.
Types of changes
Checklist
PR Type
Enhancement
Description
Replaced
ConsoleLogHandlerwithTextWriterHandlerfor flexibility.Updated
LogContextManagerto useTextWriterHandler.Modified logging tests to reflect the new handler.
Improved abstraction by utilizing
TextWriterfor log output.Changes walkthrough 📝
LogContextManager.cs
Refactored LogContextManager to use TextWriterHandlerdotnet/src/webdriver/Internal/Logging/LogContextManager.cs
ConsoleLogHandlerwithTextWriterHandler.GlobalContextinitialization to use the new handler.AsyncLocalinitialization syntax.TextWriterHandler.cs
Introduced TextWriterHandler for flexible log outputdotnet/src/webdriver/Internal/Logging/TextWriterHandler.cs
ConsoleLogHandlertoTextWriterHandler.Console.Errorwith aTextWriterparameter.TextWriter.LogTest.cs
Updated logging tests for TextWriterHandlerdotnet/test/common/Internal/Logging/LogTest.cs
TextWriterHandlerinstead ofConsoleLogHandler.